package org.snowin.common;

import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.List;

public class Main implements Runnable {
    static InitialEnvironment initialEnv;
    static List<String> caseList;
    static HashMap<String, String> configMap;
    private static URLClassLoader classloader = (URLClassLoader) ClassLoader.getSystemClassLoader();

    public static void main(String[] args) {
        initialEnv = new InitialEnvironment();
        configMap = initialEnv.getWebDrivers();
        caseList = new FindCaseNames().findCaseList();
        runCase(classloader);
    }

    public static void start(URLClassLoader urlClassLoader) {
        initialEnv = new InitialEnvironment();
        configMap = initialEnv.getWebDrivers();
        caseList = new FindCaseNames().findCaseList();
        runCase(urlClassLoader);
    }

    private static void runCase(URLClassLoader urlClassLoader) {

        Engine localEngine;
        if (urlClassLoader != null) localEngine = new Engine(configMap, caseList, initialEnv, urlClassLoader);
        else localEngine = new Engine(configMap, caseList, initialEnv);

    }


    @Override
    public void run() {


        initialEnv = new InitialEnvironment();
        configMap = initialEnv.getWebDrivers();
        caseList = new FindCaseNames().findCaseList();


        runCase(classloader);

    }
}
